//
//  FirstViewController.m
//  WYThemeManager
//
//  Created by ios on 2017/1/9.
//  Copyright © 2017年 Wy. All rights reserved.
//

#import "FirstViewController.h"
#import "ThemeManager.h"

@interface FirstViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *wTableView;
@property(nonatomic,copy)NSMutableArray *data;


@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.data = [NSMutableArray arrayWithObjects:@"红",@"黄",@"蓝",@"默认", nil];
    
    self.wTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.wTableView.delegate = self;
    self.wTableView.dataSource = self;
    [self.view addSubview:self.wTableView];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *Cell = @"Cell";
    
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:Cell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
       
    }
    cell.textLabel.text = self.data[indexPath.row];
    //可设置 主题色 或自定义颜色
    cell.textLabel.textColor = [[ThemeManager shareInstance] getThemeColor];
    // cell.textLabel.font = [UIFont systemFontOfSize:[[ThemeManager shareInstance] getThemeFont]]; 
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
            //红
            [[ThemeManager shareInstance] setThemeColor:RGBA(227, 53, 94, 1.0)];
            // 发送一个kThemeDidChangeNotification的通知，切换主题
            break;
        case 1:
            //黄
            [[ThemeManager shareInstance] setThemeColor:RGBA(227, 198, 94, 1.0)];
            break;
        case 2:
            //蓝
            [[ThemeManager shareInstance] setThemeColor:RGBA(58, 147, 195, 1.0)];
            break;
        case 3:
            //默认
            [[ThemeManager shareInstance] setThemeColor:RGBA(74, 125, 112, 1.0)];
            break;
            
        default:
            break;
    }
    
     [[NSNotificationCenter defaultCenter] postNotificationName:kThemeColorChangeNotification object:nil];
    
    [self.wTableView reloadData];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
